package taller2.controller.listeners.evaluateMeButtons;

import java.awt.event.ActionEvent;
import java.util.ArrayList;

import taller2.interfaces.AlgorithmApplicator;
import taller2.interfaces.Graph;
import taller2.interfaces.Node;
import taller2.model.factorys.GraphFactory;
import taller2.model.graph.algorithms.FordFulkersonApplicator;
import taller2.view.windows.supervisor.FordFulkersonSupervisorWindow;

public class FordFulkersonEvaluateMeButtonListener extends EvaluateMeButtonListener{

	public FordFulkersonEvaluateMeButtonListener(AlgorithmApplicator aplicator) {
		super(aplicator);
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		menu.unselectButtons();
		
		FordFulkersonApplicator ff = (FordFulkersonApplicator)aplicator;
		
		String path = ff.getStartingGraphPath();
		String solPath = ff.getSolGraphPath();
		
		if((path != null) && (solPath != null)){
			Graph g,sol;
		
			boolean directed = ff.wasDirected();
			if (directed){
				g = GraphFactory.directedGgraphInstance();
				sol = GraphFactory.directedGgraphInstance();

			}else{
				g = GraphFactory.undirectedGraphInstance();
				sol = GraphFactory.undirectedGraphInstance();
			}
		
			g.load(path);
			sol.load(solPath);

			g.unselectNodes();
			g.unselectConnections();
		
			ArrayList<Node> nodes = g.getNodes();
			int cantNodes = nodes.size();
		
			if(cantNodes > 0)
				new FordFulkersonSupervisorWindow(g,sol);
		}
	}

}
